<template>
  <div>
    <h3>求和结果为：{{ sum }}</h3>
    <h3>当前求和放大10倍为：{{ enlarge }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="increment(n)">两数相加</button>
    <h3 style="color: red">Movie组件的总电影数是：{{ movieList.length }}</h3>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions } from "vuex";
export default {
  name: "Calculate",
  data() {
    return {
      n: 1, //用户选择的数字
    };
  },
  computed: {
    //借助 mapState 生成计算属性，从 state 中读取数据（对象写法）
    ...mapState({ sum: "sum", movieList: "movieList" }),

    //借助 mapGetters 生成计算属性，从 getters中读取数据。（对象写法）
    ...mapGetters({ enlarge: "enlarge" }),
  },
  methods: {
    //借助 mapActions 生成对应的方法，方法中会调用 dispatch 去联系 actions (对象写法)
    ...mapActions({ increment: "increment" }),
  },
};
</script>

<style>
</style>